﻿<%@ Page Title="" Language="C#" MasterPageFile="../Examples.Master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="DotNetSources.Web.UI.Buttons.Examples.Examples._9_DataGrid.Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="contentDescription" runat="server">
    Buttons with confirm box used in DataGrid.
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentExample" runat="server">
    Result from server:
    <asp:Label runat="server" ID="lblResult" ForeColor="Red" /><br />
    <hr />
    <asp:GridView runat="server" ID="gridView1">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <dns:LinkButton ID="LinkButton1" runat="server" Text="Delete" OnCommand="DoSomethingClick"
                        CommandName="Delete" CommandArgument='<%# Eval("DelId") %>' ConfirmText="Do you want to really delete this item?" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <hr />
    <strong>Code:</strong>
    <div class="code">
<pre>
ASPX:
&lt;asp:GridView runat="server" ID="gridView2"&gt;
        &lt;Columns&gt;
            &lt;asp:TemplateField&gt;
                &lt;ItemTemplate&gt;
                    &lt;dns:LinkButton ID="LinkButton1" runat="server" Text="Delete" OnCommand="DoSomethingClick"
                        CommandName="Delete" CommandArgument='&lt;%# Eval("DelId") %&gt;' ConfirmText="Do you want to really delete this item?" /&gt;
                &lt;/ItemTemplate&gt;
            &lt;/asp:TemplateField&gt;
        &lt;/Columns&gt;
    &lt;/asp:GridView&gt;
    
C#:
    public partial class Default : BoxContextPage {

        protected void Page_Load(object sender, EventArgs e) {
            DataItemList dil = new DataItemList();
            dil.Add(new DataItem("aaaaa", "1"));
            dil.Add(new DataItem("bbbbb", "2"));
            dil.Add(new DataItem("ccccc", "3"));
            dil.Add(new DataItem("ddddd", "4"));
            dil.Add(new DataItem("eeeee", "5"));
            dil.Add(new DataItem("fffff", "6"));

            gridView1.DataSource = dil;
            gridView1.DataBind();
        }

        protected void DoSomethingClick(Object sender, CommandEventArgs e) {
            lblResult.Text = string.Format("Command name: {0}, Command argument: {1}", e.CommandName, e.CommandArgument);
        }

    }

    public class DataItem {
        private string delId;

        public string DelId {
            get { return delId; }
            set { delId = value; }
        }
        private string value;

        public string Value {
            get { return value; }
            set { this.value = value; }
        }

        public DataItem(string value, string id) {
            this.value = value;
            this.delId = id;
        }

    }

    public class DataItemList : List&lt;DataItem&gt; {

    }
    
</pre>
    </div>
</asp:Content>
